﻿@using IEMSOFT.EasyHotel.Admin.Models
@using IEMSOFT.EasyHotel.Common
@using IEMSOFT.Foundation
@{
    ViewBag.Title = "报表统计";
}
@section header
{
}
@{
    var currentUser = ViewBag.CurrentUser as UserModel;
}
<div class="easyui-tabs">
    <div title="日报查询" style="padding: 10px">
        <div>
            <form id="fmDayReportSearchCondition">
                <div class="fitem">
                    <label>查询日期：</label>
                    <input class="easyui-datebox" name="fromDate" data-options="formatter:myformatter,parser:myparser" id="dtFromDate_DayReport" />
                    -
                    <input class="easyui-datebox" name="endDate" data-options="formatter:myformatter,parser:myparser" id="dtEndDate_DayReport" />
                </div>
                <div class="fitem">
                    <label>房型:</label>
                    <select id="cbRoomType_DayReport" class="easyui-combobox" name="roomTypeId"
                        data-options="url:'/roomtype/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                    </select>
                </div>
                <div class="fitem">
                    <label>房客来源：</label>
                    <select id="cbTravelAgencyId_DayReport" class="easyui-combobox" name="travelAgencyId"
                        data-options="url:'/travelagency/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                    </select>
                </div>
                <div class="fitem">
                    <label>支付方式：</label>
                    <select class="easyui-combobox" name="payTypeId" id="cbPayTypeId_DayReport"
                        data-options="url:'/paytype/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                    </select>
                </div>
                @if (currentUser.RoleId == RoleType.GroupLeader.ToInt())
                {
                    <div class="fitem">
                        <label>所在分店:</label>
                        <select class="easyui-combobox" name="subHotelId"
                            data-options="url:'/subhotel/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                        </select>
                    </div>
                }
                <div>
                    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="searchDayReport()" style="width: 90px" id="linkDaySearch">查询</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="printDayReport()" style="width: 90px" id="linkDayPrint">打印</a>
                    @if (currentUser.RoleId == RoleType.Reception.ToInt())
                    {
                        <span style="color: red">注意：仅仅统计您本人操作过的订单，所有订单统计需要【店长】权限</span>
                    }
                    else if (currentUser.RoleId == RoleType.HotelManager.ToInt())
                    {
                        <span style="color: red">注意：仅仅统计本店订单，所有订单统计需要【集团领导】权限</span>
                    }
                </div>
            </form>
        </div>
        <br />
        <table id="dgDayReport" class="easyui-datagrid" pagination="true" data-options="showFooter: true"
            rownumbers="true" fitcolumns="true" singleselect="false" striped="true" ctrlselect="true"
            pagelist="[20,30,60,80,100,150,200]" pagesize="80">
            <thead>
                <tr>
                    <th field="subHotelName">分店</th>
                    <th field="billNo">订单号</th>
                    <th field="isHourRoomStr">钟点房</th>
                    <th field="roomNo">房间</th>
                    <th field="customerName">房客姓名</th>
                    <th field="travelAgencyName">房客来源</th>
                    <th field="roomTypeName">房型</th>
                    <th field="checkinDate">入住时间</th>
                    <th field="checkoutDate">退房时间</th>
                    <th field="totalDaysOrHours">入住(天数/小时)</th>   
                    <th field="priceForDayOrHour">每(天/小时房费)</th>
                    <th field="minFeeForHourRoomStr">钟点房最低房费</th>
                    <th field="roomTotalFee">房费</th>
                    <th field="consumeFee">消费金额</th>
                    <th field="consumeItem">消费项目</th>
                    <th field="payTypeName">支付方式</th>
                    <th field="comments">其他备注</th>
                    <th field="createUserFullName">创建者</th>
                    <th field="updateUserFullName">更新者</th>                  
                </tr>
            </thead>
        </table>
    </div>
    <div title="月报查询" style="padding: 10px">
        <form id="fmMonthReportSearchCondition">
            <div class="fitem">
                <label>查询月份：</label>
                <select class="easyui-combobox" name="fromYear" style="width: 60px;"
                    data-options="url:'/misc/yearoption',method:'get',valueField:'value',textField:'text'">
                </select>
                <select class="easyui-combobox" name="fromMonth" style="width: 45px;"
                    data-options="url:'/misc/monthoption',method:'get',valueField:'value',textField:'text'">
                </select>
                -
                <select class="easyui-combobox" name="endYear" style="width: 60px;"
                    data-options="url:'/misc/yearoption',method:'get',valueField:'value',textField:'text'">
                </select>
                <select class="easyui-combobox" name="endMonth" style="width: 45px;"
                    data-options="url:'/misc/monthoption',method:'get',valueField:'value',textField:'text'">
                </select>
            </div>
            <div class="fitem">
                <label>房型:</label>
                <select id="cbRoomType_MonthReport" class="easyui-combobox" name="roomTypeId"
                    data-options="url:'/roomtype/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                </select>
            </div>
            <div class="fitem">
                <label>房客来源：</label>
                <select id="cbTravelAgencyId_MonthReport" class="easyui-combobox" name="travelAgencyId"
                    data-options="url:'/travelagency/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                </select>
            </div>
            <div class="fitem">
                <label>支付方式：</label>
                <select class="easyui-combobox" name="payTypeId" id="cbPayTypeId_MonthReport"
                    data-options="url:'/paytype/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                </select>
            </div>
            @if (currentUser.RoleId == RoleType.GroupLeader.ToInt())
            {
                <div class="fitem">
                    <label>所在分店:</label>
                    <select class="easyui-combobox" name="subHotelId"
                        data-options="url:'/subhotel/option?defaultText=%E5%85%A8%E9%83%A8',method:'get',valueField:'value',textField:'text'">
                    </select>
                </div>
            }
            <div>
                <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="searchMonthReport()" style="width: 90px" id="linkMonthSearch">查询</a>
                <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="printMonthReport()" style="width: 90px" id="linkMonthPrint">打印</a>
                @if (currentUser.RoleId == RoleType.Reception.ToInt())
                {
                    <span style="color: red">注意：仅仅统计您本人操作过的订单，所有订单统计需要【店长】权限</span>
                }
                else if (currentUser.RoleId == RoleType.HotelManager.ToInt())
                {
                    <span style="color: red">注意：仅仅统计本店订单，所有订单统计需要【集团领导】权限</span>
                }
            </div>
        </form>
        <br />
        <table id="dgMonthReport" class="easyui-datagrid" pagination="true" data-options="showFooter: true"
               rownumbers="true" fitcolumns="true" singleselect="false" striped="true" ctrlselect="true"
               pagelist="[20,30,60,80,100,150,200]" pagesize="80">
            <thead>
                <tr>
                    <th field="month">月份</th>
                    <th field="billsCount">订单数</th>
                    <th field="billsRoomTotalFee">房费</th>
                    <th field="billsConsumeTotalFee">消费</th>
                    <th field="billsTotalFee">累计</th>
                </tr>
            </thead>
        </table>
    </div>

</div>
<div id="divDayReportPrint" style="display:none">
</div>
<div id="divMonthReportPrint" style="display:none">
</div>
@section Scripts
{
    <script type="text/javascript">
        $(function () {
            $('#dgDayReport').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', []);
            $('#dgMonthReport').datagrid({ loadFilter: pagerFilter }).datagrid('loadData', []);
            $('#dtFromDate_DayReport').datebox('setValue', new Date().Format('yyyy-MM-dd'));
            $('#dtEndDate_DayReport').datebox('setValue', new Date().Format('yyyy-MM-dd'));
        });

        function printDayReport() {
            $('#linkDayPrint span span').eq(0).text("处理中");
            $.post('/report/printday',
                   $('#fmDayReportSearchCondition').serialize(),
                   function (data) {
                       $('#linkDayPrint span span').eq(0).text("打印");
                       $('#divDayReportPrint').empty();
                       $('#divDayReportPrint').append(data);
                       $('#divPrintDayReportConfirm').printArea();
                   });
        }

        function printMonthReport() {
            $('#linkMonthPrint span span').eq(0).text("处理中");
            $.post('/report/printmonth',
                   $('#fmMonthReportSearchCondition').serialize(),
                   function (data) {
                       $('#linkMonthPrint span span').eq(0).text("打印");
                       $('#divMonthReportPrint').empty();
                       $('#divMonthReportPrint').append(data);
                       $('#divPrintMonthReportConfirm').printArea();
                   });
        }

        function searchDayReport() {
            var msgTitle = '日报查询';
            var actionUrl = '/report/SearchDayReport';
            $('#linkDaySearch span span').eq(0).text("正在查询");
            $.post(actionUrl,
                   $('#fmDayReportSearchCondition').serialize(),
                   function (data) {
                       $('#linkDaySearch span span').eq(0).text("查询");
                       var msg = '';
                       if (data.msg.length != 0) {
                           $.each(data.msg, function () {
                               msg = data.msg + msg + '<br/>';
                           });
                           $.messager.alert(msgTitle, msg, 'error');
                       }
                       else {

                           var result = {
                               total: data.data.length,
                               rows: data.data,
                               footer: [{
                                   subHotelName: "总房费：",
                                   billNo: 0
                               }, { subHotelName: "总消费：", billNo: 0 },{ subHotelName: "总累计：", billNo: 0 }]
                           }
                           $.each(data.data, function (index, value) {
                               result.footer[0].billNo = result.footer[0].billNo + value.roomTotalFee;//总房费
                               result.footer[1].billNo = result.footer[1].billNo + value.consumeFee;//总消费
                               result.footer[2].billNo = result.footer[0].billNo + result.footer[1].billNo;//累计
                           });
                           result.footer[2].billNo = result.footer[2].billNo.toFixed(2);

                           $('#dgDayReport').datagrid('loadData', result);
                           $('#dgDayReport').datagrid('getPager').pagination('select');
                       }
                   });
        }

        function searchMonthReport() {
            var msgTitle = '月报查询';
            var actionUrl = '/report/SearchMonthReport';
            $('#linkMonthSearch span span').eq(0).text("正在查询");
            $.post(actionUrl,
                   $('#fmMonthReportSearchCondition').serialize(),
                   function (data) {
                       $('#linkMonthSearch span span').eq(0).text("查询");
                       var msg = '';
                       if (data.msg.length != 0) {
                           $.each(data.msg, function () {
                               msg = data.msg + msg + '<br/>';
                           });
                           $.messager.alert(msgTitle, msg, 'error');
                       }
                       else {
                           var result = {
                               total: data.data.length,
                               rows: data.data,
                               footer: [{
                                   month: "总房费：",
                                   billsCount: 0
                               }, { month: "总消费", billsCount: 0 }, { month: "总累计", billsCount: 0 }]
                           }
                           $.each(data.data, function (index, value) {
                               result.footer[0].billsCount = result.footer[0].billsCount + value.billsRoomTotalFee;//总房费
                               result.footer[1].billsCount = result.footer[1].billsCount + value.billsConsumeTotalFee;//总消费
                               result.footer[2].billsCount = result.footer[0].billsCount + result.footer[1].billsCount;//累计
                           });
                           result.footer[2].billsCount = result.footer[2].billsCount.toFixed(2);
                           $('#dgMonthReport').datagrid('loadData', result);
                           $('#dgMonthReport').datagrid('getPager').pagination('select');
                       }
                   });
        }
    </script>
}
